/**
 * 
 */
package smallChanges.statements;

import java.util.List;

import smallChanges.Tokenization.TokenSet;

/**
 * @author jspacco
 *
 */
public abstract class CompoundStatement extends Statement
{
	/*
	 * header is the if/else, while or for part of the loop
	 * body is the list of statements making up the body
	 */
	private StatementHeader headerStmt;
	private StatementList body;

	public CompoundStatement(TokenSet allTokensInSet) {
		super(COMPOUND_STATEMENT, allTokensInSet);
	}
	
	protected CompoundStatement(String stmtType, TokenSet tokenSet)
	{
	    super(stmtType, tokenSet);
	}
    
	String toStringHelper(int depth)
	{
		return makePadding(depth) +getHeaderStmt().getImage() +
		"\n" +makePadding(depth)+
		" (overall coords " +getCoords()+ ")," +
		" (header coords " +getHeaderStmt().getCoords()+ "),"+
		" body has " + getBody().size()+" stmts\n"+
		getBody().toStringHelper(depth);
	}
    
    List<Statement> flattenHelper(List<Statement> list) {
        getHeaderStmt().flattenHelper(list);
        getBody().flattenHelper(list);
        return list;
    }
    
    public String getImage() {
        return getHeaderStmt().getImage() +" "+ getBody().getImage();
    }


	/**
	 * @return the header
	 */
	public SingleStatement getHeaderStmt()
	{
		return headerStmt;
	}

	/**
	 * @param header the header to set
	 */
	public void setHeaderStmt(StatementHeader header)
	{
	    header.setChild(this);
	    header.setParent(this);
		this.headerStmt = header;
	}

	/**
	 * @return the body
	 */
	public StatementList getBody()
	{
		return body;
	}

	/**
	 * @param body the body to set
	 */
	public void setBody(StatementList body)
	{
	    for (Statement s : body) {
	        s.setParent(this);
	    }
		this.body = body;
	}
	/*
	public boolean contains(Statement stmt)
	{
	    return this.contains(stmt.getTokensInRange().getFirst());
	}*/
}
